/*
* Copyright 2018 Shanxi Lu'an Taihang Laihui Net Tech co.,LTD.
*/
package com.laihuichuxing.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 *
 * @author: Qinxuefeng
 * @since: 1.0
 * Create Date Time: 2018/12/29 16:26
 * Update Date Time:
 */

public class Composite extends Component {

    private List<Component> children = new ArrayList<Component>();

    public Composite(String name) {
        super(name);
    }

    @Override
    void add(Component component) {
        children.add(component);
    }

    @Override
    void del(Component component) {
        children.remove(component);
    }

    @Override
    public void display(int depat) {
        System.out.println(depat+"-"+this.name);
        for (Component component :children){
            component.display(depat + 2);
        }
    }
}
